package com.example.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.entity.Person;
import com.example.mapper.PersonMapper;
import com.example.service.PersonService;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@RequiredArgsConstructor
public class PersonServiceImpl extends ServiceImpl<PersonMapper, Person> implements PersonService {

    // 日志对象（SLF4J）
    private static final Logger log = LoggerFactory.getLogger(PersonServiceImpl.class);

    private final PersonMapper personMapper;

    @Override
    public List<Person> getAllPersons() {
        log.info("查询所有人员信息");
        return personMapper.selectList(null); // 无查询条件
    }

    @Override
    public Person getPersonById(Long id) {
        log.info("查询ID为{}的人员信息", id);
        return personMapper.selectById(id);
    }

    @Override
    public boolean addPerson(Person person) {
        log.info("新增人员：{}", person);
        return personMapper.insert(person) > 0;
    }

    @Override
    public boolean updatePerson(Long id, Person person) {
        log.info("更新ID为{}的人员信息：{}", id, person);
        person.setId(id); // 确保ID一致
        return personMapper.updateById(person) > 0;
    }

    @Override
    public boolean deletePerson(Long id) {
        log.info("删除ID为{}的人员", id);
        return personMapper.deleteById(id) > 0;
    }
}